package com.neusoft.hifly.rpc.app.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.hifly.core.log.Log;
import com.neusoft.hifly.core.pojo.ApiCode;
import com.neusoft.hifly.core.pojo.ApiResponse;
import com.neusoft.hifly.rpc.app.dao.IDatasourceDao;
import com.neusoft.hifly.rpc.app.domain.DatasourceDTO;
import com.neusoft.hifly.rpc.app.service.IDatasourceService;

/**
 * Title: 统一用户服务
 * <p>
 * Description: 数据源接口
 * <p>
 * Copyright: 2019
 * <p>
 * Company: 东软汉枫
 *
 * @author lh_neu
 * @version 1.0.0
 */
@Service("datasourceService")
public class DatasourceServiceImpl implements IDatasourceService {

	@Autowired(required = false)
	private IDatasourceDao datasourceDao;

	/**
	 * 查询默认策略
	 *
	 * @param logicId
	 *            数据源逻辑ID
	 * @return 对象
	 */
	@Override
	public DatasourceDTO getByLogicId(final long logicId) {
		final ApiResponse<DatasourceDTO> result = datasourceDao.getByLogicId(logicId);

		if (result.getCode() == ApiCode.ERROR.getCode()) {
			Log.error(result.getMessage());
			return null;
		}

		return result.getData();
	}

}
